package com.feicheng.house.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feicheng.house.entity.Card;
import com.feicheng.house.mapper.CardMapper;
import com.feicheng.house.result.ResultInfo;
import com.feicheng.house.service.ICardService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author feichengTech
 * @since 2021-11-06
 */
@Service
public class CardServiceImpl extends ServiceImpl<CardMapper, Card> implements ICardService {

	@Override
	public ResultInfo addCard(Card card) {
		return ResultInfo.success(this.save(card));
	}

	@Override
	public ResultInfo deleteCard(Integer cardId) {
		Card card = this.getById(cardId);
		card.setDeleteFlag(false);
		return ResultInfo.success(this.updateById(card));
	}

	@Override
	public ResultInfo updateCard(Card card) {
		return ResultInfo.success(this.updateById(card));
	}

	@Override
	public ResultInfo getOneCard(Integer cardId) {
		return ResultInfo.success(this.getById(cardId));
	}

	@Override
	public ResultInfo getListCard(Integer currentPage, Integer pageSize) {
		QueryWrapper<Card> cardWrapper = new QueryWrapper<Card>();
		cardWrapper.eq("delete_flag", true);
		IPage<Card> pageInfo = new Page<Card>(currentPage,pageSize);
		return ResultInfo.success(this.page(pageInfo,cardWrapper));
	}

}
